//
//  UIImage+JQFYCornerRandius.m
//  JQFY
//
//  Created by 代辉 on 2017/9/26.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "UIImage+JQFYCornerRandius.h"

@implementation UIImage (JQFYCornerRandius)

- (UIImage *)imageWithCornerRadius:(CGFloat)radius {
    
    CGRect rect = (CGRect){0.f, 0.f, self.size};
    
    UIGraphicsBeginImageContextWithOptions(self.size, NO, UIScreen.mainScreen.scale);
    
    CGContextAddPath(UIGraphicsGetCurrentContext(),
                     [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
    CGContextClip(UIGraphicsGetCurrentContext());
    [self drawInRect:rect];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
